package com.maxdu.labs.stt.utils;

import android.util.Log;

import com.maxdu.labs.stt.constants.Constants;
import com.maxdu.labs.stt.models.Training;
import com.maxdu.labs.stt.models.TrainingType;
import com.maxdu.labs.stt.models.User;
import com.maxdu.labs.stt.models.db.UserDBHelper;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.SaveCallback;

public class InitializeDBThisIsAFAKEClass {
	public void initializeDb(){
		
		//initialize Users
		User u1 = new User("10204598502186605","Maxence Duthoo XX");
		User u2 = new User("1498793737033534","Maxence Du XX");
		User u3 = new User("763611733703526","Max Du XX");
		
		UserDBHelper uHelper = new UserDBHelper();
		uHelper.updateToCloud(u1);
		uHelper.updateToCloud(u2);
		uHelper.updateToCloud(u3);
		
		//initialize Trainings
		
	}
	
	private void addDummiesTraining(){
		String tplanId = "020927ab-0567-4b5f-b5a4-119b85e96450";
		String maxenceId = "10204598502186605";
		String maxDuId = "1498793737033534";
		String maxenceDuId = "763611733703526";
		long tuesday = 1409029200000L;
		long monday = 1408942800000L;
		long wednesday = 1409115600000L;
		long thursday = 1409202000000L;
		
		Training trainingM1 = new Training(tplanId,maxenceId,monday,TrainingType.TYPE_CLIMBING);
		Training trainingM2 = new Training(tplanId,maxenceId,tuesday,TrainingType.TYPE_CLIMBING);
		Training trainingM3 = new Training(tplanId,maxenceId,wednesday,TrainingType.TYPE_CLIMBING);
		Training trainingM4 = new Training(tplanId,maxenceId,thursday,TrainingType.TYPE_CLIMBING);
		
		Training trainingM5 = new Training(tplanId,maxDuId,wednesday,TrainingType.TYPE_CLIMBING);
		Training trainingM6 = new Training(tplanId,maxDuId,thursday,TrainingType.TYPE_CLIMBING);
		
		saveTraining(trainingM1);
		saveTraining(trainingM2);
		saveTraining(trainingM3);
		saveTraining(trainingM4);
		saveTraining(trainingM5);
		saveTraining(trainingM6);
	}
	
	private void saveTraining(final Training training){
		ParseObject trainingParseObject = new ParseObject(Training.PARSE_DB_TABLENAME);
		
		trainingParseObject.put(Training.PARSE_DB_FIELD_TPLANID, training.getTPlanId());
		trainingParseObject.put(Training.PARSE_DB_FIELD_USERID,  training.getUserId());
		trainingParseObject.put(Training.PARSE_DB_FIELD_DATE,  training.getDate());
		trainingParseObject.put(Training.PARSE_DB_FIELD_TRAINING_TYPE,  training.getType());
		
		trainingParseObject.saveInBackground(new SaveCallback() {
			
			@Override
			public void done(ParseException e) {
				if (e == null){
					//Log.d(Constants.LOG_TAG, "we successfully updated to Cloud the Training:  TPlan[" + tplan.getId() + "] - User [" + training.getUserId() + "] - day[" + training.getDate() );
		      		//Toast.makeText(AddTrainingActivity.this, getResources().getString(R.string.training_added), Toast.LENGTH_LONG).show();
		  			//Intent intent = new Intent(AddTrainingActivity.this, MainActivity.class);
		  			//startActivity(intent);
				}else{
					//Log.e(Constants.LOG_TAG, "we couldn't update to Cloud the Training:  TPlan[" + tplan.getId() + "] - User [" + training.getUserId() + "] - day[" + training.getDate() );
				}
				
			}
		});
	}
}
